/**
 * 图片资源加载类
 * @author zhouzhanglin
 * @returns {Loader}
 */
Loader = function()
{
	DisplayObjectContainer.call(this); //调用父类构造
	this.className="Loader";
	
	this._content ; //加载的内容
	this._urlRequest;  //http请求
	this._isDispose = false;
};
FLASH.extend(Loader,DisplayObjectContainer); //继承自DisplayObjectContainer

//获取加载完成的图片
Loader.prototype.getContent = function(){ return this._content ;};

/**
 * 加载一个资源
 * @param urlRequest 类型为URLRequest对象
 */
Loader.prototype.load = function( urlRequest )
{
	this._isDispose = false;
	this._urlRequest = urlRequest ;
	
	var img = new Image();
	var _self = this;
	img.onload = function(){
		if(_self._isDispose) return ;
		
		var evt = new Event( Event.COMPLETE);
		evt._currentTarget = _self ;
		evt._target = _self ;
		_self._width = img.width;
		_self._height = img.height;
		//获取图片
		var bitmapData = new BitmapData( img.width,img.height );
		bitmapData._setImage(img);
		var bmp = new Bitmap(bitmapData);
		_self._content = bmp ;
		//抛出完成事件
		_self.dispatchEvent( evt );
	};
	img.src = urlRequest.url ;
} ;
/**
 * 卸载和停止加载的内容
 */
Loader.prototype.unloadAndStop = function()
{
	this._isDispose = true ;
	if(this._content && this._content._bitmapData){
		this._content._bitmapData._dispose();
	}
	this._content = null ;
};

//=============私有方法=====================
/**
 * 画图
 * @param globalAlpha 
 * @param context
 */
Loader.prototype._draw =function( globalAlpha,context )
{
	if(this._content)
	{
		context.globalAlpha=globalAlpha ;
		context.setTransform( this._worldModelMatrix._a ,this._worldModelMatrix._b,this._worldModelMatrix._c,this._worldModelMatrix._d,
				this._worldModelMatrix._tx,this._worldModelMatrix._ty );
		context.drawImage( this._content,0,0);
	}
};